package com.aditya.videoutil.util;

import java.io.File;

import android.os.Environment;

public class VideoUtilPathManager {

  private static File getRoot() {
    return new File(Environment.getExternalStorageDirectory(), "videoutil");
  }

  public static File getNewFilePath(String fileName) {
    File file = getRoot();

    if (!file.exists()) {
      file.mkdirs();
    }

    file = getFile(file, fileName);

    return file;
  }

  private static File getFile(File file, String fileName) {

    File returnFile = new File(file, fileName.substring(0, fileName.lastIndexOf(".")) + "_VU"
        + fileName.substring(fileName.lastIndexOf(".")));
    int i = 0;
    while (returnFile.exists()) {
      returnFile = new File(file, fileName.substring(0, fileName.lastIndexOf(".")) + "_VU(" + ++i + ")"
          + fileName.substring(fileName.lastIndexOf(".")));
    }

    return returnFile;
  }

  public static String getFileNameWithoutExtn(String filename) {
    return filename.substring(0, filename.lastIndexOf("."));
  }

  public static File getRootDirectory() {
    File dir = getRoot();
    if (!dir.exists()) {
      dir.mkdirs();
    }

    return dir;
  }

}
